import request from '@/utils/request'
import apiConfig from '@/api/config'
import { useUserStore } from '@/pinia/modules/user'
import FileSaver from 'file-saver'
import qs from 'qs'
// import qs from 'qs'

// 登陆
export const login = data => {
  return request({
    url: `${apiConfig.baseApi}/auths/login`,
    method: 'post',
    // headers: {
    //   'Content-Type': 'application/x-www-form-urlencoded'
    // },
    data
  })
}

export const uploadBigFile = params => {
  return request({
    url: `${apiConfig.baseApi}/auths/captcha`,
    method: 'get',
    params
  })
}

// 获取养老机构下拉选项
export const getYLOrgOptions = params => {
  return request({
    url: `${apiConfig.businessApi}/pension-organizations/all`,
    method: 'get',
    params
  })
}

// 机构列表1
export const service_quality_tasks_getOrg = data => {
  return request({
      url: `${apiConfig.businessApi}/service-quality-tasks/simple-org`,
      method: 'get',
      params:data
  })
}
// 机构列表2
export const service_quality_tasks_getOrg2 = data => {
  return request({
      url: `${apiConfig.businessApi}/service-quality-tasks/below-org`,
      method: 'get',
      params:data
  })
}

// 获取社区养老服务机构账户管理列表-新版
export const getOrgAccountListLast = params => {
  return request({
    url: `${apiConfig.businessApi}/homeOrganization/dict`,
    method: 'get',
    params
  })
}

// 单点登录
export const ssoLogin = data => {
  return request({
    url: `${apiConfig.baseApi}/sso/login`,
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  })
}

// 获取用户密码规范信息
export const getUserCheckPwd = () => {
  return request({
    url: `${apiConfig.baseApi}/auths/checkPwd`,
    method: 'get'
  })
}


// 获取后台菜单
export const asyncMenu = params => {
  return request({
    url: `${apiConfig.baseApi}/auths/resources`,
    method: 'get',
    params
  })
}

// 获取验证码
export const getCaptcha = params => {
  return request({
    url: `${apiConfig.baseApi}/auths/captcha`,
    method: 'get',
    params
  })
}

// 获取字典
export const getDictTree = params => {
  return request({
    url: `${apiConfig.baseApi}/dicts/tree`,
    method: 'get',
    params
  })
}

// 获取地区区划
export const gerAreaByCode = data => {
  return request({
    url: `${apiConfig.baseApi}/areas/next-children/${data}`,
    method: 'get'
  })
}
// 获取地区区划
export const getAreaInfo = data => {
  return request({
    url: `${apiConfig.baseApi}/areas/${data}`,
    method: 'get'
  })
}

// 退出登陆
export const loginOut = () => {
  return request({
    url: `${apiConfig.baseApi}/auths/logout`,
    method: 'get'
  })
}

// 导出
export const downLoad = (params,url,api) => {
  return request({
    url:`${api}${url}`,
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 导入
export const importFile = (params,url,api) => {
  return request({
    url:`${api}${url}`,
    method: 'post',
    params,
    responseType: 'blob'
  })
}

// 下载文件
export const downLoadFile = async (ids,fileName) => {
  const blob = await request({
    url:`${useUserStore().fileUrl}/batch_download?ids=${ids}&package_name=${fileName}`,
    method: 'get',
    responseType: 'blob'
  })
  FileSaver.saveAs(blob, `${fileName}.zip`)
}








// -------------------------------------------
// 以下代码为示例api
export const deleteApisByIds = (data) => {
  return request({
    url: '/deleteApisByIds',
    method: 'delete',
    data
  })
}

export const getUserInfo = (params) => {
  return request({
    url: '/user/getCurrentUser',
    method: 'get',
    params
  })
}

export const setSelfInfo = (data) => {
  return request({
    url: '/authority/setDataAuthority',
    method: 'post',
    data
  })
}

export const getSystemState = () => {
  return request({
    url: '/system/getServerInfo',
    method: 'post',
    donNotShowLoading: true
  })
}



export const asyncMenu2 = (data) => {
  return request({
    url: '/fileUploadAndDownload/breakpointContinue',
    method: 'post',
    donNotShowLoading: true,
    headers: { 'Content-Type': 'multipart/form-data' },
    data
  })
}

export const createTemp = (data) => {
  return request({
    url: '/autoCode/createTemp',
    method: 'post',
    data,
    responseType: 'blob'
  })
}



